package com.team.bus.module.menu.model;

import com.team.bus.module.organization.model.Organization;
import com.team.bus.module.role.model.Role;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "tmenu",schema = "miaoxu")
public class Menu implements java.io.Serializable {

	private static final long serialVersionUID = -3319899811823116199L;
	private String id;
	private Menu menu;
	private String text;
	private String iconcls;
	private String url;
	private String sstyle;
	private int orderno;
	private Set<Menu> menus = new HashSet<Menu>(0);
	private Set<Role> roles = new HashSet<Role>(0);
	private Set<Organization> organizations = new HashSet<Organization>(0);

	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid")
	@Column(name = "id", unique = true, nullable = false, length = 50)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pid")
	public Menu getMenu() {
		return this.menu;
	}

	public void setMenu(Menu menu) {
		this.menu = menu;
	}

	@Column(name = "text", length = 500)
	public String getText() {
		return this.text;
	}

	public void setText(String text) {
		this.text = text;
	}

	@Column(name = "iconcls", length = 50)
	public String getIconcls() {
		return this.iconcls;
	}

	public void setIconcls(String iconcls) {
		this.iconcls = iconcls;
	}

	@Column(name = "url", length = 600)
	public String getUrl() {
		return this.url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "menu")
	public Set<Menu> getMenus() {
		return this.menus;
	}

	
	public void setMenus(Set<Menu> menus) {
		this.menus = menus;
	}

	@Column(name = "orderno")
	public int getOrderno() {
		return orderno;
	}

	public void setOrderno(int orderno) {
		this.orderno = orderno;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "trole_menu", schema = "", 
	joinColumns = { @JoinColumn(name = "menuid", nullable = false, updatable = false) }, 
	inverseJoinColumns = { @JoinColumn(name = "roleid", nullable = false, updatable = false) })
	public Set<Role> getRoles() {
		return roles;
	}
	
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "tmenu_organization", schema = "", 
	joinColumns = { @JoinColumn(name = "menuid", nullable = false, updatable = false) }, 
	inverseJoinColumns = { @JoinColumn(name = "organizationid", nullable = false, updatable = false) })
	public Set<Organization> getOrganizations() {
		return organizations;
	}

	public void setOrganizations(Set<Organization> organizations) {
		this.organizations = organizations;
	}

	@Column(name = "sstyle", length = 50)
	public String getSstyle() {
		return sstyle;
	}

	public void setSstyle(String sstyle) {
		this.sstyle = sstyle;
	}
}